﻿using Admin.NET.Application.Util.Extension;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Radius.NET.Interface.Kingdee.Entity
{
    /// <summary>
    /// 生产汇报单
    /// </summary>
    public class PRD_MORPT : KingdeePubClass
    {

        public PRD_MORPT_Model Model { get; set; }

        #region 生产汇报单表头
        public class PRD_MORPT_Model
        {

            public int FID { set; get; }
            public FBillType FBillType { set; get; }
            public string FDocumentStatus { set; get; }
            public DateTime FDate { set; get; }
            public FPrdOrgId FPrdOrgId { set; get; }
            public FWorkshipIdH FWorkshipIdH { set; get; }
            public string FDescription { set; get; }
            public F_asdg_Base1 F_asdg_Base1 { set; get; }
            public List<PRD_MORPT_FEntity> FEntity { set; get; }
        }
        #endregion

        #region 生产汇报单明细
        public class PRD_MORPT_FEntity
        {
            public int FEntryID { set; get; }
            public string FSrcBillNo { set; get; }
            public string FSrcEntryId { set; get; }
            public bool FIsNew { set; get; }
            public FMaterialId FMaterialId { set; get; }
            public string FProductType { set; get; }
            public FReportType FReportType { set; get; }
            public F_asdg_Base F_asdg_Base { set; get; }
            public double F_asdg_Decimal2 { set; get; }
            public FUnitID FUnitID { set; get; }
            public double F_asdg_Decimal { set; get; }
            public double F_asdg_Decimal1 { set; get; }
            public FWorkshipID FWorkshipId { set; get; }
            public FShiftGroupId FShiftGroupId { set; get; }
            public FLot FLot { set; get; }
            public FDeptId FDeptId { set; get; }
            public FStockLocId FStockLocId { set; get; }
            public string FMtoNo { set; get; }
            public bool FCheckProduct { set; get; }
            public bool FIsEntrust { set; get; }
            public string FSrcBillType { set; get; }  //源单类型
            public string FMoBillNo { set; get; }  //生产订单号

            public FAuxPropId FAuxPropId { set; get; }
            public double FHumanQty { set; get; }
            public double FMachineQty { set; get; }
            public FMaterialUnitID FMaterialUnitID { set; get; }
            public string FStartTime { set; get; }
            public string FEndTime { set; get; }
            public string FTimeUnitId { set; get; }
            public string FMoEntrySeq { set; get; }
            public string FStandHourUnitId { set; get; }
            public string FProjectNo { set; get; }
            public double FStdManHour { set; get; }
            public double FHrPrepareTime { set; get; }
            public double FHrWorkTime { set; get; }
            public double FMacPrepareTime { set; get; }
            public double FMacWorkTime { set; get; }
            public string FDescriptionE { set; get; }
            public string FSrcInterId { set; get; }
            public string FSrcEntrySeq { set; get; }
            public string FMoId { set; get; }
            public string FMoEntryId { set; get; }
            public FBaseUnitId FBaseUnitId { set; get; }
            public FStockInOrgId FStockInOrgId { set; get; }
            public FBomId FBomId { set; get; }
            public string FOwnerTypeId { set; get; }
            public FStockId FStockId { set; get; }
            public FOwnerId FOwnerId { set; get; }
            public double FCostRate { set; get; }
            public FSNUnitID FSNUnitID { set; get; }
            public string FSNQty { set; get; }
            public string FProduceDate { set; get; }
            public bool FISBACKFLUSH { set; get; }
            public string FExpiryDate { set; get; }
            public double FMOMAINENTRYID { set; get; }
            public string FStockInSelQty { set; get; }
            public string FBaseStockInSelQty { set; get; }
            public string FPickMtrlSelQty { set; get; }
            public string FBasePickMtrlSelQty { set; get; }
            public bool FIsFirstinspect { set; get; }
            public bool F_asdg_Date { set; get; }
            public double? FFinishQty { set; get; }
            public List<FSerialSubEntity> FSerialSubEntity { set; get; }
            public List<FEntity_Link> FEntity_Link { set; get; }
        }
        #endregion
        public class F_asdg_Base1
        {
            public string FNumber { set; get; }
        }
        public class F_asdg_Base
        {
            public string FSTAFFNUMBER{set; get; }
        }

        public class FEntity_Link
        {
            public string FEntity_Link_FRuleId { set; get; }
            public string FEntity_Link_FSTableName { set; get; }
            public double FEntity_Link_FSBillId { set; get; }
            public double FEntity_Link_FSId { set; get; }
        }
        public class FAuxPropId
        {
            public FAUXPROPID__FF100002_Model FAUXPROPID__FF100001 {  set; get; }
            public FAUXPROPID__FF100001_Model FAUXPROPID__FF100002 { set; get; }
            public class FAUXPROPID__FF100002_Model
            {
                public string FNumber { set; get;}
            }
            public class FAUXPROPID__FF100001_Model
            {
                public string FNumber { set; get; }
            }
        }
        public class FSerialSubEntity
        {
            
        }
        public object BuildData(MaterialIssuePlan issue)
        {
            return new PRD_MORPT()
            {
                Model = new PRD_MORPT_Model()
                {
                    FID = 0,
                    FBillType = new()
                    {
                        FNumber = "SCHBD01_SYS"
                    },
                    FDocumentStatus = "",
                    FDate = DateTime.Now,//工程单实际完成日期
                    FPrdOrgId = new()
                    {
                        FNumber = KingdeeConfigConst.ORGID
                    },
                    FWorkshipIdH = new()
                    {
                        FNumber = ""
                    },
                    FDescription = "",
                    F_asdg_Base1 = new()
                    {
                        FNumber = "SCDD01_SYS"
                    },
                    FEntity = new List<PRD_MORPT_FEntity>() {
                    new () {
                        FEntryID= 0,
                        FSrcBillNo= issue.No.Split("_")[0],  //源单编号
                        FSrcEntryId= JSON.Deserialize<dynamic>(issue.Summary1).FTreeEntity_FEntryId,
                        FIsNew= false,
                        FMaterialId= new () {
                            FNumber= issue.Inventory_ID
                        },
                        FProductType="1" ,  //产品类型
                        FReportType= new()
                        {
                            FNumber= "HBLX01_SYS"   //生产汇报类型
                        },
                        F_asdg_Base = new (){
                            FSTAFFNUMBER=""
                        },
                        F_asdg_Decimal2=0,
                        FUnitID= new(){
                            FNumber= "kg"  //单位
                        },
                        F_asdg_Decimal = 0,
                        F_asdg_Decimal1 = 0,
                        FWorkshipId = new()
                        {
                            FNumber =issue.DeptID is null ? "P&T04.01.01": issue.DeptID//车间
                        },
                        FShiftGroupId= new(){
                            FNumber= ""  //班组
                        },
                        FLot= new(){
                            FNumber= issue.No  //  批次号
                        },
                        FDeptId= new(){
                            FNumber= "" //部门
                        },
                        FStockLocId= new (){},  //仓位
                        FMtoNo= "",  //计划跟踪号
                        FCheckProduct= false,
                        FIsEntrust= false,
                        FSrcBillType= "PRD_MO",  //源单类型
                        FMoBillNo= issue.No.Split("_")[0],  //生产订单号

                        FAuxPropId= new (){
                            FAUXPROPID__FF100002= new(){
                                FNumber=""
                            },
                            FAUXPROPID__FF100001= new(){
                                FNumber= ""
                            }
                        },
                        FHumanQty= 0,
                        FMachineQty=0,
                        FMaterialUnitID= new(){
                            FNumber= "kg"  //物料生产单位
                        },
                        FStartTime="",
                        FEndTime="",
                        FTimeUnitId= "",  //时间单位
                        FMoEntrySeq= issue.No.Split("_")[1],
                        FStandHourUnitId= "",  //单位标准工时单位
                        FProjectNo= "",  //项目编号
                        FStdManHour= 0,  //单位标准工时
                        FHrPrepareTime= 0,//人员准备工时
                        FHrWorkTime= 0, //人员实作工时
                        FMacPrepareTime= 0, //机器准备工时
                        FMacWorkTime= 0, //机器实作工时
                        FDescriptionE="" , //备注
                        FSrcInterId= JSON.Deserialize<dynamic>(issue.Summary1).FID, //源单内码 
                        FSrcEntrySeq= issue.No.Split("_")[1],
                        FMoId= JSON.Deserialize<dynamic>(issue.Summary1).FID, //源单内码 
                        FMoEntryId= JSON.Deserialize<dynamic>(issue.Summary1).FTreeEntity_FEntryId, //生产订单分录ID
                        FBaseUnitId= new(){
                            FNumber= "kg"
                        },
                        FStockInOrgId= new(){
                            FNumber= KingdeeConfigConst.ORGID  //入库组织
                        },
                        FBomId= new(){
                            FNumber= issue.BOM  //BOM版本
                        },
                        FOwnerTypeId= "BD_OwnerOrg", //货主类型
                        FStockId= new(){
                            FNumber= "CK002"  //仓库
                        },
                        FOwnerId= new(){
                            FNumber= KingdeeConfigConst.ORGID //货主
                        },
                        FCostRate= 0,  //成本权重
                        FSNUnitID= new (){
                            FNumber="kg"  //序列号单位
                        },
                        FSNQty= "", //序列号单位数量
                        FProduceDate= issue.ActFinDate?.ParseToString(), //生产日期
                        FISBACKFLUSH= true,  //倒冲领料
                        FExpiryDate= "2022/12/30",  //有效期至
                        FMOMAINENTRYID= JSON.Deserialize<dynamic>(issue.Summary1).FTreeEntity_FEntryId,  //生产订单主产品分录
                        FStockInSelQty= "",//合格品入库数量
                        FBaseStockInSelQty= "", //基本单位合格品入库数量
                        FPickMtrlSelQty= "",  //领料选单数量
                        FBasePickMtrlSelQty= "",//基本单位领料选单数量
                        FIsFirstinspect= false,
                        F_asdg_Date = false,
                        FFinishQty = issue.InJarAfter, //完成数量
                        FSerialSubEntity= new List<FSerialSubEntity>(),
                        FEntity_Link = new List<FEntity_Link>()
                        {
                            new()
                            {
                                FEntity_Link_FRuleId = "PRD_MO2MORPT",
                                FEntity_Link_FSTableName = "T_PRD_MOENTRY",
                                FEntity_Link_FSBillId = JSON.Deserialize<dynamic>(issue.Summary1).FID,
                                FEntity_Link_FSId = JSON.Deserialize<dynamic>(issue.Summary1).FTreeEntity_FEntryId
                            }
                        }
                    }
                        }
                }
            };
        }
    }
}
